<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="年份." :labelCol="labelCol" :wrapperCol="wrapperCol" prop="year">
              <a-input v-model="model.year" placeholder="请输入年份."  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="月份" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="month">
              <a-input v-model="model.month" placeholder="请输入月份"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="据点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="site">
              <a-input v-model="model.site" placeholder="请输入据点"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="成本分群" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="costGroup">
              <a-input v-model="model.costGroup" placeholder="请输入成本分群"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="成本分群说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="groupDesc">
              <a-input v-model="model.groupDesc" placeholder="请输入成本分群说明"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="营业成本表分类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="costClass">
              <a-input v-model="model.costClass" placeholder="请输入营业成本表分类"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="成本域" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="costDomain">
              <a-input v-model="model.costDomain" placeholder="请输入成本域"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="成本域说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="domainDesc">
              <a-input v-model="model.domainDesc" placeholder="请输入成本域说明"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="料号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="partNo">
              <a-input v-model="model.partNo" placeholder="请输入料号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="品名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productName">
              <a-input v-model="model.productName" placeholder="请输入品名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="规格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="spec">
              <a-input v-model="model.spec" placeholder="请输入规格"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="存货科目编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="invAcctCode">
              <a-input v-model="model.invAcctCode" placeholder="请输入存货科目编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="存货科目说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="invAcctDesc">
              <a-input v-model="model.invAcctDesc" placeholder="请输入存货科目说明"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="产品特征" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productFeature">
              <a-input v-model="model.productFeature" placeholder="请输入产品特征"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="批号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="batchNo">
              <a-input v-model="model.batchNo" placeholder="请输入批号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="成本单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="unit">
              <a-input v-model="model.unit" placeholder="请输入成本单位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="期初数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="begQty">
              <a-input v-model="model.begQty" placeholder="请输入期初数量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="期初单位成本" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="begUnitCost">
              <a-input v-model="model.begUnitCost" placeholder="请输入期初单位成本"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="期初金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="begAmount">
              <a-input v-model="model.begAmount" placeholder="请输入期初金额"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本期入库数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentInQty">
              <a-input v-model="model.currentInQty" placeholder="请输入本期入库数量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本期入库金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentInAmount">
              <a-input v-model="model.currentInAmount" placeholder="请输入本期入库金额"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本期平均单价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="avgPrice">
              <a-input v-model="model.avgPrice" placeholder="请输入本期平均单价"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="材料" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="materialPrice">
              <a-input v-model="model.materialPrice" placeholder="请输入材料"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="人工" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="laborPrice">
              <a-input v-model="model.laborPrice" placeholder="请输入人工"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="加工" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="processPrice">
              <a-input v-model="model.processPrice" placeholder="请输入加工"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="制费一" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="manuFee1">
              <a-input v-model="model.manuFee1" placeholder="请输入制费一"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="制费二" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="manuFee2">
              <a-input v-model="model.manuFee2" placeholder="请输入制费二"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="制费三" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="manuFee3">
              <a-input v-model="model.manuFee3" placeholder="请输入制费三"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="制费四" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="manuFee4">
              <a-input v-model="model.manuFee4" placeholder="请输入制费四"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="制费五" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="manuFee5">
              <a-input v-model="model.manuFee5" placeholder="请输入制费五"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本期出库数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentOutQty">
              <a-input v-model="model.currentOutQty" placeholder="请输入本期出库数量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本期出库金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentOutAmount">
              <a-input v-model="model.currentOutAmount" placeholder="请输入本期出库金额"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="期末数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="endQty">
              <a-input v-model="model.endQty" placeholder="请输入期末数量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="期末金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="endAmount">
              <a-input v-model="model.endAmount" placeholder="请输入期末金额"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="期末调整金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="adjustAmount">
              <a-input v-model="model.adjustAmount" placeholder="请输入期末调整金额"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="默认库位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="defaultLocation">
              <a-input v-model="model.defaultLocation" placeholder="请输入默认库位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="库位名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="locationName">
              <a-input v-model="model.locationName" placeholder="请输入库位名称"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'Axcq530ChAllForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/ch/axcq530ChAll/add",
          edit: "/ch/axcq530ChAll/edit",
          queryById: "/ch/axcq530ChAll/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>